// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PhysicalObjectDescription.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Microsoft.Robotics.PhysicalObjects
{
    using System;
    using System.Runtime.Serialization;
    using Microsoft.Robotics.Numerics;

    /// <summary>
    /// Enumeration of commonly found object shapes
    /// </summary>
    [DataContract]
    public enum PhysicalObjectShape
    {
        /// <summary>
        /// Unknown shape
        /// </summary>
        [EnumMemberAttribute]
        Undefined,

        /// <summary>
        /// Cylindrical shape
        /// Dimensions: Diameter and Height
        /// </summary>
        [EnumMemberAttribute]
        Cylinder,

        /// <summary>
        /// Regularly shaped box
        /// Dimensions: Length Width, Height
        /// </summary>
        [EnumMemberAttribute]
        BoxRegular,

        /// <summary>
        /// Generic object that is manipulated with top down grip only
        /// </summary>
        [EnumMemberAttribute]
        TopDownWithOrientation,

        /// <summary>
        /// Ellipsoid base shape
        /// </summary>
        [EnumMemberAttribute]
        Ellipsoid,
    }

    /// <summary>
    /// High level description of the type and simple geometry of a physical object that can
    /// be manipulated or observed
    /// </summary>
    [DataContract]
    public class PhysicalObjectDescription 
    {
        /// <summary>
        /// Description for an undefined object
        /// </summary>
        public static readonly PhysicalObjectDescription None = new PhysicalObjectDescription(PhysicalObjectShape.Cylinder, 0.0, 0.0, 0.0, 0.0, "None");

        /// <summary>
        /// Description of dove box
        /// </summary>
        public static readonly PhysicalObjectDescription BoxSoap = new PhysicalObjectDescription(PhysicalObjectShape.BoxRegular, 0.097, 0.186, 0.063, 678.0, "SoapBox");

        /// <summary>
        /// Description of net gear ethernet switch box
        /// </summary>
        public static readonly PhysicalObjectDescription BoxNetgear = new PhysicalObjectDescription(PhysicalObjectShape.BoxRegular, 0.165, 0.217, 0.080, 678.0, "NetGearBox");

        /// <summary>
        /// Description of tomato can
        /// </summary>
        public static readonly PhysicalObjectDescription CanTomato = new PhysicalObjectDescription(PhysicalObjectShape.Cylinder, 0.075, 0.110, 0.075, 411.0, "TomatoCan");

        /// <summary>
        /// Description of can of shoe string potatoes
        /// </summary>
        public static readonly PhysicalObjectDescription CanPotato = new PhysicalObjectDescription(PhysicalObjectShape.Cylinder, 0.102, 0.207, 0.102, 411.0, "PotatoCan");

        /// <summary>
        /// Description of the Bagel
        /// </summary>
        public static readonly PhysicalObjectDescription Bagel = new PhysicalObjectDescription(PhysicalObjectShape.TopDownWithOrientation, 0.105, 0.033, 0.105, 100.0, "Bagel");

        /// <summary>
        /// Description of the Bagel tray
        /// </summary>
        public static readonly PhysicalObjectDescription BagelTray = new PhysicalObjectDescription(PhysicalObjectShape.TopDownWithOrientation, 0.450, 0.0355, 0.025, 100.0, "OutputBagelTray");

        /// <summary>
        /// Description of the large up face calibration disc
        /// </summary>
        public static readonly PhysicalObjectDescription CalibrationDiscUpface = new PhysicalObjectDescription(PhysicalObjectShape.TopDownWithOrientation, 0.050, 0.010, 0.050, 150.0, "Upfacing calibrationDisc");

        /// <summary>
        /// Description of the calibration disc
        /// </summary>
        public static readonly PhysicalObjectDescription CalibrationDisc = new PhysicalObjectDescription(PhysicalObjectShape.TopDownWithOrientation, 0.030, 0.030, 0.030, 150.0, "CalibrationDisc");

        /// <summary>
        /// Absence of any object for a background subtraction
        /// </summary>
        public static readonly PhysicalObjectDescription BackgroundImage = new PhysicalObjectDescription(PhysicalObjectShape.Undefined, 0.0, 0.0, 0.0, 0.0, "BackgroundImage");

        /// <summary>
        /// Initializes a new instance of the <see cref="PhysicalObjectDescription" /> class
        /// </summary>
        /// <param name="shape">Object shape</param>
        /// <param name="widthInM">Object width in meter</param>
        /// <param name="heightInM">Object height in meter</param>
        /// <param name="depthInM">Object depth in meter</param>
        /// <param name="weightInGr">Object weight in grams</param>
        /// <param name="description">Object description</param>
        public PhysicalObjectDescription(PhysicalObjectShape shape, double widthInM, double heightInM, double depthInM, double weightInGr, string description)
        {
            this.Shape = shape;
            this.WeightInGr = weightInGr;
            this.WidthInM = widthInM;
            this.HeightInM = heightInM;
            this.DepthInM = depthInM;
            this.Description = description;
        }

        /// <summary>
        /// Gets the shape type
        /// </summary>
        [DataMember]
        public PhysicalObjectShape Shape { get; private set; }

        /// <summary>
        /// Gets the object width in meters.
        /// </summary>
        [DataMember]
        public double WidthInM { get; private set; }

        /// <summary>
        /// Gets the object height in meters.
        /// </summary>
        [DataMember]
        public double HeightInM { get; private set; }

        /// <summary>
        /// Gets the object depth in meters.
        /// </summary>
        [DataMember]
        public double DepthInM { get; private set; }

        /// <summary>
        /// Gets the object weight (mass) in grams
        /// </summary>
        [DataMember]
        public double WeightInGr { get; private set; }

        /// <summary>
        /// Gets object description
        /// </summary>
        [DataMember]
        public string Description { get; private set; }

        /// <summary>
        /// Returns string description of object
        /// </summary>
        /// <returns>String description</returns>
        public override string ToString()
        {
            return this.Shape.ToString();
        }
    }
}
